package com.study.samsung.Control;

import cn.hutool.json.JSON;
import com.alibaba.fastjson.JSONObject;
import com.study.samsung.Entity.*;
import com.study.samsung.Service.AddressService;
import com.study.samsung.Service.GoodsService;
import com.study.samsung.Service.IndexSearchService;
import com.study.samsung.Service.OrdersService;
import com.study.samsung.Utils.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/quxiao")
public class QuxiaoServlet extends BaseServlet {
    OrdersService os = new OrdersService();
    AddressService ad = new AddressService();

    IndexSearchService iss = new IndexSearchService();
    GoodsService gds = new GoodsService();

    @Override
    public String excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String d = request.getParameter("d");
        Integer did = Integer.parseInt(d);
        session.setAttribute("did",did);

        List<Commodity> newgoods = iss.selectnew();
        List<Succession> selectxl = iss.selectxl();

        request.setAttribute("newgoods",newgoods);
        request.setAttribute("selectxl",selectxl);

        Object user = session.getAttribute("user");
        if (user!=null){
            User nowuser = (User) user;
            Integer uid = nowuser.getUid();

            session.setAttribute("cartcount",gds.cartcount(uid));
        }
        return "f:quxiao";
    }
    public String addshow(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String Did = request.getParameter("did");
        Integer did = Integer.parseInt(Did);
        List<Orders> orders = os.selectOrdersaid(did);
        Integer aid = orders.get(0).getAid();
        Address address = ad.selectOne(aid);
        System.out.println("根据did查出来的地址:"+address);
        String json = JSONObject.toJSONString(address);
        return json;
    }
}
